<template>
    <layout title="毛笔社区">
        <div class="community">
            <div class="search">
                <div class="search_l">
                    <div class="sea_l">
                        <img :src="showImage('edu/img/seach.png')" />
                    </div>
                    <div class="sea_r" @click="changeshow">
                    	输入关键字搜索
                    </div>

                </div>
                <a  href="/member/collect">
                    <div class="search_r">我的互动</div>
                </a>
            </div>

            <div class="new_box">
                <div class="new_l">热门分类</div>
                <a href="/forum/category"><div class="new_r">查看更多</div></a>
            </div>

            <div class="new_list">
                <ul class="list_ul">
                    <li class="cell" v-for="(item, index) in type" :key="index">
                        <a :href="'/forum/category?forumTypeId=' + item.id">
                            <div class="padding">
                                <img :src="showImage(item.icon, '?x-oss-process=image/resize,m_fixed,h_50,w_50')" />
                                <div :key="index">{{item.name}}</div>
                            </div>
                        </a>
                    </li>
                </ul>
            </div>

            <!--精选问答-->

            <div class="jx_box">
                <div class="new_l">精选问答</div>
                <a href="/answer">
                    <div class="new_r">查看更多</div>
                </a>
            </div>

            <div class="jx_list">
                <ul class="list_ul">
                    <li class="cell" v-for="(item, index) in forumIndex.forumAnswers" :key="index">
                        <a class="padding" :href="'/answer/detail/' + item.postDTO.id">
                            <img :src="showImage(item.forumIcon, '?x-oss-process=image/resize,m_fixed,h_200,w_200')">
                            <div class="flex_img"></div>
                            <div class="flex_top">{{item.forumName}}</div>
                            <div class="flex_tops">有{{item.postDTO.answerCount }}个笔友帮你解答</div>

                            <div class="p_footer">
                                <div class="title">{{item.postDTO.title}}</div>
                                <div class="answer">
                                    <span class="title-d">答</span>
                                    <p class="t_content">如果你无法简洁大表达你的想法如果你的想法</p>
                                </div>

                            </div>

                        </a>
                    </li>
                </ul>
            </div>

            <div class="conetnt">

                <div class="meark" v-for="(item, index) in forumIndex.posts" :key="index">
                    <a class="padding" :href="'/forum/detail/' + item.id">
                        <div class="c_top">{{item.title}}！</div>
                        <div class="c_img" v-if="item.images.length > 0">

                        	<img v-for="img in item.images"  v-if="item.images.length < 2" style="height: 3.6rem;"  :src="showImage(img, '?x-oss-process=image/resize,m_fixed,w_300')"/>

                            <img v-for="img in item.images"  v-if="item.images.length > 1" style="height: 1.6rem;"  :src="showImage(img, '?x-oss-process=image/resize,m_fixed,w_300')"/>

                            <!--<img v-for="img in item.images" :src="showImage(img, '?x-oss-process=image/resize,m_fixed,h_200,w_200')">-->
                        </div>
                        <div class="c_fot">

                            <div class="c_left">
                                <div>{{item.answerCount}} 赞</div>
                                <div>{{item.postLikeCount}}评论</div>
                            </div>
                            <div class="c_right">来自{{item.forumName}}</div>

                        </div>
                    </a>
                </div>
            </div>

        </div>



		<div v-show="isShow" class="searchbox">
			 <div class="search">
                <div class="search_l">
                    <div class="sea_l">
                        <img :src="showImage('edu/img/seach.png')" />
                    </div>
                    <div class="sea_r">
                        <input type="text" v-model="keyword" placeholder="输入关键字搜索" />
                    </div>
                </div>
                <a  href="">
                    <div @click="changenone" class="search_r">取消</div>
                </a>
            </div>


             <div class="conetnt">
                <div class="meark" v-for="(item, index) in list" :key="index">
                    <a class="padding" :href="'/forum/detail/' + item.id">
                        <div class="c_top">{{item.title}}！</div>
                        <div class="c_img">
                            <img v-for="(img, index) in item.images" :src="img">
                        </div>
                        <div class="c_fot">

                            <div class="c_left">
                                <div>{{item.answerCount}} 赞</div>
                                <div>{{item.postLikeCount}}评论</div>
                            </div>
                            <div class="c_right">来自{{item.forumName}}</div>

                        </div>
                    </a>
                </div>
            </div>
		</div>




    </layout>
</template>
<style lang="scss">
    @import "index.scss";
</style>
<script type="text/babel">
    import { api, image } from 'framework/config.js';

    import Layout from "component/layout/standard";

    import Vue from 'vue'
    import Mint from 'mint-ui';
    Vue.use(Mint);

    export default {
        components: {
            Layout
        },
        data(){
            return {
                list: [],
                keyword: '',
            	isShow:false,
            }
        },
        computed: {
            api(){
                return api();
            },

        },
        methods: {
            showImage(url, params){
                return image(this.api.image, url, params);
            },
        	changeshow:function(){

        		this.isShow = true
        	},
        	changenone:function(){
        		this.isShow = false
        	},
            search: function () {
                if (!this.keyword || this.keyword.length == 1){
                    this.list = [];
                }
                if (this.keyword.length < 2){
                    return;
                }

                this.$http.get('/api/forum/search', {
                    params: {
                        keyword: this.keyword
                    }
                }).then((response) => {
                    if (response.status == 200){
                        let data = response.data;
                        if (data.code == 200) {
                            this.list = data.data;
                        }
                    }else{
                    }


                })
            }
        },
        watch: {
            keyword: function () {
                this.search();
            }
        },
        mounted() {
        }
    }
</script>

